﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL.EstRec;

namespace FileOps
{
    public class Catalogo
    {
        public int idCat { get; set; }
        public string nombre { get; set; }
        public string fileName { get; set; }
        public int orden { get; set; }
        public bool isActive { get; set; }
        public string fileFullName { get; set; }

        public Catalogo(string nombreCat)
        {
            this.GetCatInfo(nombreCat);
        }

        private void GetCatInfo(string nombreCompleto)
        {
            string nombre = nombreCompleto.Split('\\').Last();
            string query = "SP_ER_GET_CURRENTCATINFO @FileName= '" + nombre + "'";
            DataTable dt = new DataTable();

            try
            {
                dt = SrvDB.ExecuteQuery(query);

                if (dt.Rows.Count > 0)
                {
                    this.fileFullName = nombreCompleto;
                    this.idCat = int.Parse(dt.Rows[0]["ID_CAT"].ToString());
                    this.nombre = dt.Rows[0]["CAT_NAME"].ToString();
                    this.fileName = dt.Rows[0]["FILE_NAME"].ToString();
                    this.orden = int.Parse(dt.Rows[0]["CAT_ORDER"].ToString());
                    this.isActive = bool.Parse(dt.Rows[0]["IS_ACTIVE"].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ". " + ex.InnerException.ToString());
                throw ex;
            }
        }//

    }//end class
}
